package com.wawayaya.ui.advertcover;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wawayaya.bean.Advert;
import com.wawayaya.bean.Books;
import com.wawayaya.ui.bookcover.BookCoverHolder;
import com.wawayaya.util.ImageUtils;

import java.util.List;

import wawayaya.kids_iread.R;

/**
 * 图书封面
 */
public class AdvertCoverAdapter extends RecyclerView.Adapter<AdvertCoverHolder> {

    private Context  context;
    private List<Advert> adverts;
    private boolean   isZh;

    public AdvertCoverAdapter(Context context, boolean isZh, List<Advert> adverts) {
        this.context = context;
        this.isZh = isZh;
        this.adverts = adverts;
    }

    @Override
    public int getItemCount() {
         int count = 0;
         if( adverts.size()>3){
             count = 3;
         }else{
             count = adverts.size();
         }
        return  count;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public AdvertCoverHolder onCreateViewHolder(ViewGroup vg, final int position) {
        View v = LayoutInflater.from(context).inflate(R.layout.advert_cover, vg, false);
        return new AdvertCoverHolder(v);
    }

    @Override
    public void onBindViewHolder(final AdvertCoverHolder holder, final int position) {
        final Advert  advert = adverts.get(position);
        ImageUtils.getImageLoader().displayImage("http://10.135.195.180:8086/" + advert.getAdvertImgUri(), holder.m_iv, ImageUtils.getCoverOptions());
    }

}
